package cn.jiyun.controller;


import cn.jiyun.common.config.Result;
import cn.jiyun.entity.XmDistributionstations;
import cn.jiyun.service.IXmDistributionstationsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/xm-client/xm-distributionstations")
public class XmDistributionstationsController {


    @Autowired
    private IXmDistributionstationsService xmDistributionstationsService;


//    查询所有配送站
    @RequestMapping("findAll")
    public Result findAll(Integer current, Integer pageSize, @RequestBody XmDistributionstations xmDistributionstations) {
        Page<XmDistributionstations> page = xmDistributionstationsService.findAll(current, pageSize, xmDistributionstations);
        return Result.ok(page);
    }


//    修改锁定状态
    @RequestMapping("lockk")
    public Result lockk(@RequestBody XmDistributionstations xmDistributionstations) {
        xmDistributionstationsService.updateById(xmDistributionstations);
        return Result.ok();
    }



//    获取某个站点的信息
    @RequestMapping("findById")
    public Result findById(Integer id) {
        XmDistributionstations xmDistributionstations=xmDistributionstationsService.getById(id);
        return Result.ok(xmDistributionstations);
    }


//    根据某个名称获取站点信息
    @RequestMapping("findByName")
    public Result findByName(String name,String name2) {
        List<XmDistributionstations> address = xmDistributionstationsService.list(new QueryWrapper<XmDistributionstations>().like("address", name).or().like("detailed_address", name).like("address", name2));
        return Result.ok(address);
    }



//    添加配送站
    @RequestMapping("addDbs")
    public Result addDbs(@RequestBody XmDistributionstations xmDistributionstations) {
     if(xmDistributionstations.getId()!=null){
         xmDistributionstationsService.updateById(xmDistributionstations);
     }else{
         xmDistributionstations.setStatus(1);
         xmDistributionstations.setBuildTime(LocalDateTime.now());
         xmDistributionstations.setCount(0);
         xmDistributionstations.setCertificationStatus(1);
         xmDistributionstationsService.save(xmDistributionstations);
     }
        return Result.ok();
    }
}
